Passed
Push — master ( c59208...8079ea )
by Maxence
02:12
created

admin_pico_nav.addCustomTemplate   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
/*
2
 * CMS Pico - Integration of Pico within your files to create websites.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: admin_pico_elements */
28
/** global: admin_pico_result */
29
/** global: admin_pico_define */
30
31
var admin_pico_nav = {
32
33
	retrieveSettings: function () {
34
		$.ajax({
35
			method: 'GET',
36
			url: OC.generateUrl('/apps/cms_pico/admin/settings'),
37
			data: {}
38
		}).done(function (res) {
39
			admin_pico_result.displaySettings(res);
40
		});
41
	},
42
43
44
	addCustomTemplate: function () {
45
		$.ajax({
46
			method: 'PUT',
47
			url: OC.generateUrl('/apps/cms_pico/admin/templates'),
48
			data: {
49
				template: admin_pico_elements.cms_pico_new_template.val()
50
			}
51
		}).done(function (res) {
52
			admin_pico_result.displaySettings(res);
53
		});
54
	},
55
56
57
	removeCustomTemplate: function (template) {
58
		$.ajax({
59
			method: 'DELETE',
60
			url: OC.generateUrl('/apps/cms_pico/admin/templates'),
61
			data: {
62
				template: template
63
			}
64
		}).done(function (res) {
65
			admin_pico_result.displaySettings(res);
66
		});
67
	},
68
69
70
	interactionCurrentTemplate: function (div) {
71
		var name = div.attr('data-name');
72
		div.find('TD.delete').on('click', function () {
73
			admin_pico_nav.removeCustomTemplate(name);
74
		});
75
	},
76
77
78
79
	addCustomTheme: function () {
80
		$.ajax({
81
			method: 'PUT',
82
			url: OC.generateUrl('/apps/cms_pico/admin/themes'),
83
			data: {
84
				theme: admin_pico_elements.cms_pico_new_theme.val()
85
			}
86
		}).done(function (res) {
87
			admin_pico_result.displaySettings(res);
88
		});
89
	},
90
91
92
	removeCustomTheme: function (theme) {
93
		$.ajax({
94
			method: 'DELETE',
95
			url: OC.generateUrl('/apps/cms_pico/admin/themes'),
96
			data: {
97
				theme: theme
98
			}
99
		}).done(function (res) {
100
			admin_pico_result.displaySettings(res);
101
		});
102
	},
103
104
105
	interactionCurrentTheme: function (div) {
106
		var name = div.attr('data-name');
107
		div.find('TD.delete').on('click', function () {
108
			admin_pico_nav.removeCustomTheme(name);
109
		});
110
	},
111
112
113
114
	generateTmplCustomTemplate: function (entry) {
115
		var div = $('#tmpl_custom_template');
116
		if (!div.length) {
117
			return;
118
		}
119
120
		var tmpl = div.html();
121
		tmpl = tmpl.replace(/%%name%%/g, escapeHTML(entry));
122
		return tmpl;
123
	},
124
125
126
	generateTmplCustomTheme: function (entry) {
127
		var div = $('#tmpl_custom_theme');
128
		if (!div.length) {
129
			return;
130
		}
131
132
		var tmpl = div.html();
133
		tmpl = tmpl.replace(/%%name%%/g, escapeHTML(entry));
134
		return tmpl;
135
	}
136
137
138
};